//
//  MCDiscountPayCell.swift
//  StoreManage
//
//  Created by MC on 2017/12/19.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit



class MCClerkManageCell: UITableViewCell {
    
    var model : MCClerkManageModel = MCClerkManageModel() {
        didSet {
            iconImageView.sd_setImage(with: URL.init(string: model.picture), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
            nameLabel.text = model.nickName
            phoneLabel.text = model.userName
            let levelTuples = MCLevelConversion(level: model.level)
            identifierLabel.text = levelTuples.levelName
            
            if levelTuples.level == MCRole_manager {
                identifierLabel.backgroundColor = UIColor.MCAssist_C
            } else if levelTuples.level == MCRole_assistant {
                identifierLabel.backgroundColor = UIColor.MCAssist_B
            } else {
                identifierLabel.backgroundColor = UIColor.MCAssist_F
            }
        }
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = UIColor.white
        
        
        self.addSubview(iconImageView)
        iconImageView.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(self)
            make.left.equalTo(10)
            make.size.equalTo(CGSize.init(width: 44, height: 44))
        }
        
        self.addSubview(arrowImageView)
        arrowImageView.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(self)
            make.right.equalTo(-10)
            make.size.equalTo(CGSize.init(width: 8, height: 14))
        }

        self.addSubview(nameLabel)
        nameLabel.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(arrowImageView.snp.left).offset(-10)
            make.centerY.equalTo(self)
        }
        
        self.addSubview(lineView)
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.bottom.right.equalTo(0)
            make.height.equalTo(1)
        }
        
        self.addSubview(identifierLabel)
        identifierLabel.snp.remakeConstraints { (make) ->Void in
            make.bottom.equalTo(iconImageView.snp.centerY).offset(-2)
            make.left.equalTo(iconImageView.snp.right).offset(10)
            make.size.equalTo(CGSize.init(width: 46, height: 16))
        }
        
        self.addSubview(phoneLabel)
        phoneLabel.snp.remakeConstraints { (make) ->Void in
            make.top.equalTo(iconImageView.snp.centerY).offset(2)
            make.left.equalTo(iconImageView.snp.right).offset(10)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.cornerRadius = 22
        imageView.layer.masksToBounds = true
        imageView.layer.borderColor = UIColor.MCGray_light.cgColor
        imageView.layer.borderWidth = 1
        return imageView
    }()
    
    lazy var identifierLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(10)
        label.textColor = UIColor.white
        label.textAlignment = NSTextAlignment.center
        label.backgroundColor = UIColor.orange
        label.layer.cornerRadius = 8
        label.layer.masksToBounds = true
        return label
    }()

    lazy var phoneLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(14)
        label.textColor = UIColor.MCWords
        return label
    }()

    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(15)
        label.textColor = UIColor.MCWords
        label.textAlignment = NSTextAlignment.right
        return label
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()
    
    lazy var arrowImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "Reuse_arrow")
        return imageView
    }()
}





